<?php

namespace Home\Controller;

/**
 * Description of AccountController.class控制器实例
 *
 * @author songanwei
 * @date 2016-1-4
 */
class InterfaceServerPageController extends ParentController {

    protected function _initialize() {
        parent::_initialize();
        $this->validateUtil = new \Org\Util\Validate();
    }

    /**
     * 接口服务界面
     * @modify wenhui 2017-11-13 创建
     */
    public function InterfaceServer() {
        $param = I('get.');

        $hotelId = $param['hotel'];

        $serverModel = D('Server');
        $serverInfoModel = D('ServerInfo');

        // 检查操作权限
        $adminAuthorityLogic = A('Common/AdminAuthority', 'Logic');
        $adminAuthorityLogic->check($hotelId);

        $interfaceServerInfo = $serverModel->field('id,sign')->select();
        $interfaceServerInfo = getArrayValueAsIndex($interfaceServerInfo, 'id');
        $serverIds = array_column($interfaceServerInfo, 'id');

        if (!empty($serverIds)) {
            $serverInfo = $serverInfoModel->field('id,server_id,language,name,description')->where(['server_id' => ['in', $serverIds]])->select();
        } else {
            $serverInfo = array();
        }
        // 获取服务接口数据
        $interfaceServerLogic = A('Common/InterfaceServer', 'Logic');
        $interfaceServer = $interfaceServerLogic->getInterfaceServerInfoByHotel($hotelId);
        $interfaceServer = getArrayValueAsIndex($interfaceServer, 'server_id');
        // 组装数据
        foreach ($serverInfo as $key => $serverItem) {
            if (isset($interfaceServerInfo[$serverItem['server_id']])) {
                if (LANG_SET == $serverItem['language']) {
                    $interfaceServerInfo[$serverItem['server_id']]['name'] = $serverItem['name'];
                    $interfaceServerInfo[$serverItem['server_id']]['description'] = $serverItem['description'];
                }
                $interfaceServerInfo[$serverItem['server_id']]['applyInfo'] = isset($interfaceServer[$serverItem['server_id']]) ? $interfaceServer[$serverItem['server_id']] : array();
                // 文档路径
                if ($interfaceServerInfo[$serverItem['server_id']]['sign'] == 'getwechatcode') {
                    $interfaceServerInfo[$serverItem['server_id']]['downurl'] = '/Public/uclbrt/files/getwechatcode.docx';
                } else {
                    $interfaceServerInfo[$serverItem['server_id']]['downurl'] = '';
                }
            }
        }
        unset($serverItem);
        $interfaceServerInfo = array_values($interfaceServerInfo);

        $this->assign('serverInfo', $interfaceServerInfo);
        $this->display();
    }
    public function WindowsClient() {
        $url = "http://ob2p0ov9p.bkt.clouddn.com/client/qrmaster/QRInn_Installer_v1.0.0.0.exe";
        
        Vendor('phpRPC.phprpc_client');
        $client = new \PHPRPC_Client(C('MANAGE_PUBLIC_URL'));
        $client->setEncryptMode(3);
        $RPCData = array(
            'flag' => 'uclbrt',
            'time' => time(),
            'isLatest'=> true,
        );
        $v = $client->getMeizhuVersion($RPCData);
        if(!empty($v['url'])){
            $url = $v['url'];
        }
        $this->assign("download_url", $url . '?' . rand());
        
        $this->display();        
    }    
}